package org.springsecuritylearn.repository.jvm.lession1.demo1;

import java.util.HashMap;

/**
 * @author hyf
 * @Title: ${file_name}
 * @Package org.springsecuritylearn.repository.jvm.lession1.demo1
 * @Description: ${todo}
 * @date 2018/5/5下午9:04
 */
public class StopWorldTest {

    public  static class MyThread extends Thread{
        HashMap map=new HashMap();

        @Override
        public void run() {
           while(true){
               if (map.size()*5120/1024/1024>=900){
                   map.clear();
                   System.out.println("clean map");
               }
               byte[] b1;
               for (int i=0;i<100;i++){
                   b1=new byte[5120];
                   map.put(System.nanoTime(),b1);
               }
               try {
                   Thread.sleep(1);
               } catch (InterruptedException e) {
                   e.printStackTrace();
               }
           }
        }
    }
    public static class PrintThread extends Thread{
        public static final long startTime=System.currentTimeMillis();
        @Override
        public void run() {
            while(true){
                long t=System.currentTimeMillis()-startTime;
                System.out.println(t/1000+"."+t%1000);
                try {
                    Thread.sleep(100);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }
    }

    public static void main(String[] args) {
        MyThread t=new MyThread();
        PrintThread p=new PrintThread();
        t.start();
        p.start();
    }


}
